package dk.mirasola.systemtraining.bridgewidgets.client.ui.editor;

import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.safehtml.shared.SafeHtml;
import dk.mirasola.systemtraining.bridgewidgets.client.i18n.EditorTexts;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape.Shape;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.shape.ShapeElement;

import java.util.List;

public class ShapeEditor extends ShapeElementsEditor implements LeafValueEditor<Shape> {
    private static EditorTexts editorTexts = GWT.create(EditorTexts.class);

    @Override
    protected SafeHtml getHelpInfo() {
        return editorTexts.shapeHelpInfo();
    }

    @Override
    protected boolean isValid(List<ShapeElement> shapeElements) {
        return Shape.validate(shapeElements);
    }

    @Override
    public void setValue(Shape value) {
        setValidatedShapeElement(value.getShapeElements());
    }

    @Override
    public Shape getValue() {
        return Shape.create(getValidatedShapeElements(), false);
    }
}
